using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Sixeyed.CacheAdapter.Management;
using Sixeyed.CacheAdapter.Interfaces;

namespace Sixeyed.CacheAdapter.CacheViewer
{
    /// <summary>
    /// Main form, displays cache contents & options for setting instance properties
    /// </summary>
    public partial class Main : Form
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public Main()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.RefreshCacheView();
        }

        private void btnSetProvider_Click(object sender, EventArgs e)
        {
            CacheProperties properties = new CacheProperties();
            DialogResult result = properties.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.RefreshCacheView();
            }
        }

        private void RefreshCacheView()
        {
            this.textBox1.Text = TransmitLocation.Current.Name;

            //get configured provider from factory:
            ICacheProviderConfiguration config = TransmitLocation.Current.GetCacheConfiguration();
            ICacheProvider provider = CacheFactory.GetProvider(TransmitLocation.Current.Provider, config);

            IEnumerator enumerator = provider.GetEnumerator();
            List<object> cacheObjects = new List<object>();
            while (enumerator.MoveNext())
            {
                cacheObjects.Add(enumerator.Current);
            }
            this.dataGridView1.DataSource = cacheObjects;
        }
    }
}